﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KD.Sms
{
    public class CacheSamplingPacking
    {

        /// <summary>
        /// 缓存 桶号 读卡失败时 替补
        /// </summary>
        public static string[] E_SamplingPailCardCache = new string[8] { "", "", "", "", "", "", "", "" };

        private static object _objLocker = new object();
        /// <summary>
        /// 当前保存的样桶
        /// </summary>
        private static Entity.SamplingInfoForPailSave E_SamplingInfoForPailSave { set; get; }

        private static List<Entity.SamplingInfoForPailSave> _listSaveData = new List<Entity.SamplingInfoForPailSave>();


        /// <summary>
        /// 
        /// </summary>
        public static Entity.SamplingInfoForPailSave E_PackingSaveValueSet
        {
            set
            {
                lock (_objLocker)
                {
                    if (value != null)
                        _listSaveData.Add(value);
                }
            }
            //set
            //{
            //    lock (_objLocker)
            //    {
            //        if (value != null)
            //        {
            //            //吴幽 封装机完成
            //            _listSaveData = new List<Entity.SamplingInfoForPailSave>();
            //            _listSaveData.Add(value);
            //        }
            //    }
            //}
        }

        /// <summary>
        /// 获取封装机当前操作对象
        /// </summary>
        public static Entity.SamplingInfoForPailSave E_PackingSaveValueGet
        {
            get
            {
                lock (_objLocker)
                {
                    return (_listSaveData == null || _listSaveData.Count == 0) ? new Entity.SamplingInfoForPailSave() : _listSaveData[0];
                }
            }
        }

        /// <summary>
        /// 当前封装对象
        /// </summary>
        public static int E_PackingObjectsCount
        {
            get
            {
                lock (_objLocker)
                {
                    return (_listSaveData == null || _listSaveData.Count == 0) ? 0 : _listSaveData.Count;
                }
            }
        }

        /// <summary>
        /// 完成当前操作
        /// </summary>
        public static void DoPackingDone()
        {
            lock (_objLocker)
            {
                if (_listSaveData != null)
                {
                    //吴幽 封装机完成 
                    //_listSaveData = new List<Entity.SamplingInfoForPailSave>();

                    if (_listSaveData.Count == 1)
                        _listSaveData = new List<Entity.SamplingInfoForPailSave>();
                    else
                        _listSaveData.RemoveAt(0);
                }
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        public static void DoInit()
        {
            _listSaveData = new List<Entity.SamplingInfoForPailSave>();
        }

        /// <summary>
        /// 获取当前点数
        /// </summary>
        /// <returns></returns>
        public static int DoGetCachePointCount(int pail)
        {
            if (_listSaveData == null || _listSaveData.Count == 0)
                return 0;
            else
            {
                Entity.SamplingInfoForPailSave model = _listSaveData.Find(c => c.E_SamplingPail == pail);
                return model == null ? 0 : model.E_SamplingPoscount;
            }
        }

        /// <summary>
        /// 获取待包装的点数
        /// </summary>
        /// <returns></returns>
        public static int DoGetCachePointCount()
        {
            if (_listSaveData == null || _listSaveData.Count == 0)
                return 0;
            else
            {
                return _listSaveData.Sum(c => c.E_SamplingPoscount);
            }
        }

    }
}
